package com.hollysys.elapi.parser;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import com.hollysys.elapi.parser.core.ELNode;
import com.hollysys.elapi.parser.core.ExpressLanguageParseException;
import com.hollysys.elapi.parser.logicflow.LogicFlow;
import com.hollysys.elapi.parser.parser.ELParser;
import com.hollysys.elapi.parser.parser.LogicFlowParser;
import com.hollysys.elapi.parser.utils.ELNodeUtil;

public class Main {

    public static void main(String[] args) {
        String jsonStr = FileUtil.readUtf8String("D:\\temp\\111\\el解析\\nodes2.json");
        LogicFlow logicFlow = JSONUtil.toBean(jsonStr, LogicFlow.class);
        String sqlTemplate = null;
        try {
            ELParser elParser = new LogicFlowParser(logicFlow);
            ELNode elNode = elParser.extractElNode();
            System.out.println(JSONUtil.toJsonStr(elNode));
            sqlTemplate = ELNodeUtil.generateEl(elNode);
        } catch (ExpressLanguageParseException e) {
            e.printStackTrace();
        }
        System.out.println(sqlTemplate);
    }
}
